
import request from "@/utils/request";
import type {
  GetAttrListApiParams,
  GetAttrListApiResponse,
  BaseSaleAttrList,
  AddOrUpdateSpuParams,
  SpuImageList,
  SpuSaleAttrList,
} from "@/api/product/model/spuModel";

const enum Api {
  getSpuList = "/admin/product",
  getBaseSaleAttrList = "/admin/product/baseSaleAttrList",
  addSpu = "/admin/product/saveSpuInfo",
  getSpuImageList = "/admin/product/spuImageList",
  getSpuSaleAttrList = "/admin/product/spuSaleAttrList",
  updateSpu = "/admin/product/updateSpuInfo",

}

export const getSpuListApi = ({
  page,
  limit,
  category3Id,
}: GetAttrListApiParams) => {
  return request.get<any, GetAttrListApiResponse>(
    Api.getSpuList + `/${page}/${limit}`,
    {
      params: {
        category3Id,
      },
    }
  );
};

export const getBaseSaleAttrListApi = () => {
  return request.get<any, BaseSaleAttrList>(Api.getBaseSaleAttrList);
};

export const addSpuApi = (data:AddOrUpdateSpuParams) =>{
  return request.post<any,null>(Api.addSpu,data)
}

export const getSpuImageListApi = (id:number) =>{
  return request.get<any,SpuImageList>(Api.getSpuImageList+`/${id}`)
}
export const getSpuSaleAttrListApi = (id:number) =>{
  return request.get<any,SpuSaleAttrList>(Api.getSpuSaleAttrList+`/${id}`)
}
export const updateSpu = (data:AddOrUpdateSpuParams) =>{
  return request.post<any,null>(Api.updateSpu,data)
}